home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 1999 #2
/
Amiga Plus CD - 1999 - No. 2.iso
/
System-Boost
/
Grafik
/
picFX
/
e-source
/
parser.e
next >
Wrap
Text File
|
1998-11-08
|
41KB
|
1,248 lines
OPT MODULE
MODULE 'tools/longreal'
MODULE 'dos/dos',
'exec/nodes','exec/ports','exec/semaphores','exec/tasks',
'graphics/rastport','cybergraphics','picasso96api'
OBJECT function
precision -> OUT_#?
type -> the type of function, FTYPE_#?
args:PTR TO LONG -> May be of different types, see below.
constant:CHAR -> TRUE if the function does not depend on x.
value:LONG -> value of the constant if constant is true (or longreal address)
nofree -> set to TRUE if the program don't want value to be freed by end()
warning -> warning messages, when using functions that will not work.
ENDOBJECT
EXPORT SET WARN_Trig,
WARN_Mod
EXPORT OBJECT project_Node
ln:ln -> base node structure
window -> window object
item -> string that appears in opened_lst
pid -> Project ID
ENDOBJECT
EXPORT OBJECT subtaskmsg
stm_Message:mn
stm_Command:INT
stm_Parameter:LONG
stm_Result:LONG
ENDOBJECT
EXPORT OBJECT subtask
st_Task:PTR TO tc /* sub task pointer */
st_Port:PTR TO mp /* allocated by sub task */
st_Reply:PTR TO mp /* allocated by main task */
st_Data:LONG /* more initial data to pass to the sub task */
st_Message:subtaskmsg /* Message buffer */
ENDOBJECT
EXPORT OBJECT planeFunc_data
projectid -> Project ID, used when referencing a project from "outside"
/***attributes storage***/
bfunc:PTR TO function
bstr:PTR TO CHAR
failure /*$RGB*/
gfunc:PTR TO function
gstr:PTR TO CHAR
height:PTR TO function
imagefile:PTR TO CHAR
left,newleft ->scroll when newleft is non-zero
loading
loadm
lock -> -1 when there's a writelock, 0 when it is free, number of readlocks otherwise
name:PTR TO CHAR
overflowhandling
projectnode:PTR TO project_Node
rfunc:PTR TO function
rstr:PTR TO CHAR
paused -> this is used by the 'state' attribute, with the 'lock' var
outputr,outputg,outputb
quiet
top,newtop -> scroll when newtop is non-zero
type
width
/***some pointers...***/
hscroll,vscroll -> scrollers of the window
app -> pointer to application
self -> pointer to ourselves
/***some useful data***/
savepixel -> true if the previous pixel must be saved
sema:ss -> data item protection
subtask:PTR TO subtask -> our sub task
rp:PTR TO rastport -> rastport for the sub task
drawn -> the last line that has been drawn to the window
calculated -> the last line that has been calculated by the subtask
ds:datestamp -> planeFunc stores the datestamp when a calculation is started
ENDOBJECT
EXPORT ENUM OUT_Integer=0, -> 32bits integer
OUT_Float32, -> 32Bits float
OUT_Float64, -> 64Bits float
OUT_OldR,OUT_OldG,OUT_OldB, -> Components of the pixel (previous calculation!)
OUT_CopyR,OUT_CopyG -> Copies the new expression (e.g. black'n'white)
ENUM FTYPE_None=0, -> When empty
FTYPE_Constant, -> args = the value of that constant or a PTR TO longreal
FTYPE_Variable, -> args=VAR_.. or CTE_..
FTYPE_Plus,FTYPE_Substr,FTYPE_Multiply,FTYPE_Divide, -> args = two pointers to two function or variable
FTYPE_Power, -> args = two pointers to two functions or variable
FTYPE_Mod,FTYPE_Max,FTYPE_Min,
/*Some single argument functions: args directely holds the address of the related function*/
FTYPE_Sin,FTYPE_Cos,FTYPE_Tan, /*trigonometric..*/
FTYPE_ASin,FTYPE_ACos,FTYPE_ATan,/*their inverses*/
/*three functions to get the value of another planeFunc object*/
FTYPE_Red,FTYPE_Green,FTYPE_Blue -> args = one LONG and two PTR TO function
DEF farray:PTR TO LONG /*Global (but private) variable containing the addresses of the operators.*/
DEF gtd, -> gtd is the address of the getdata(dat,num) PROC
dat -> dat is the address of the ProjectlistObject's data
ENUM GR_Red=0,GR_Green,GR_Blue
CONST VAR_x=-1,
VAR_y=-2,
CTE_e=-3,
CTE_pi=-4
EXPORT PROC initfuncs(gtda,data,picasso)
IF farray THEN END farray[FTYPE_Blue+1] -> Being called by the setup method of the main program,
NEW farray[FTYPE_Blue+1] -> This function risks being called twice or more times.
farray[FTYPE_None]:={enone}
farray[FTYPE_Constant]:={econst}
farray[FTYPE_Variable]:={evar}
farray[FTYPE_Plus]:={eplus}
farray[FTYPE_Substr]:={esubstr}
farray[FTYPE_Multiply]:={emultiply}
farray[FTYPE_Divide]:={edivide}
farray[FTYPE_Power]:={epower}
farray[FTYPE_Mod]:={emod}
farray[FTYPE_Max]:={emax}
farray[FTYPE_Min]:={emin}
farray[FTYPE_Sin]:={esin}
farray[FTYPE_Cos]:={ecos}
farray[FTYPE_Tan]:={etan}
farray[FTYPE_ASin]:={easin}
farray[FTYPE_ACos]:={eacos}
farray[FTYPE_ATan]:={eatan}
IF picasso
farray[FTYPE_Red]:={pred}
farray[FTYPE_Green]:={pgreen}
farray[FTYPE_Blue]:={pblue}
ELSE
farray[FTYPE_Red]:={ered}
farray[FTYPE_Green]:={egreen}
farray[FTYPE_Blue]:={eblue}
ENDIF
gtd:=gtda
dat:=data
ENDPROC
EXPORT PROC cleanfuncs() /*executed at the end of the caller program (e.g. within EXCEPT ENDPROC)*/
END farray[FTYPE_Blue+1]
ENDPROC
PROC decode(str:PTR TO CHAR,start=0,end=-1,modl=FALSE) OF function HANDLE
DEF tstr:PTR TO CHAR,f:function -> to pass a method to a variable, e.g. self.args[1]
DEF k:PTR TO LONG,lr:PTR TO longreal
DEF pos /*the index of the current operator*/, pri /*its priority*/, type /*its type*/,
bpos /*the index of the less important operator*/,bpri=5/*its priority*/, btype /*its type*/
self.nofree:=TRUE
self.end() -> remove the memory allocated in {args}, if necessary, but keeps the function structure.
self.nofree:=FALSE
IF end=-1 THEN end:=StrLen(str)-1
pos:=start-1
LOOP
pos,type:=sep(str,pos+1)
IF CtrlC() THEN Raise(126)
IF pos > end THEN JUMP out
pri:=priority(type)
IF pri <= bpri
bpos:=pos
bpri:=pri
btype:=type
ENDIF
ENDLOOP
out:
self.constant:=FALSE -> default state
IF bpri = 5 -> no operators
tstr:=String(end-start+2)
MidStr(tstr,str,start,end-start+1) /*it is probably not necessary to write the length again*/
IF StrCmp(tstr,'x')
self.type:=farray[FTYPE_Variable]
self.args:=VAR_x
ELSEIF StrCmp(tstr,'y')
self.type:=farray[FTYPE_Variable]
self.args:=VAR_y
self.constant:=TRUE
ELSEIF StrCmp(tstr,'pi')
self.type:=farray[FTYPE_Variable]
self.args:=CTE_pi
self.constant:=TRUE
ELSEIF StrCmp(tstr,'e')
self.type:=farray[FTYPE_Variable]
self.args:=CTE_e
self.constant:=TRUE
ELSEIF StrCmp(tstr,'r',1)
self.type:=farray[FTYPE_Red]
NEW k[3]
self.args:=k
pos:=findcomma(str,start+2)
IF pos=-1 /*(This is quite silly:-) If there is a mistake,*/
NEW f.create(self.precision) /*Raise. The functions are created so that end()*/
k[1]:=f /*can END them without trouble.*/
NEW f.create(self.precision)
k[2]:=f
Raise(-1)
ENDIF
k[]:=gtd(dat,Val(str+start+2))
NEW f.create(self.precision)
k[1]:=f
bpos:=findcomma(str,pos+1)
IF (bpos=-1) OR (k[]=0) -> no second comma or unexistant ID
NEW f.create(self.precision)
k[2]:=f
Raise(-1)
ENDIF
f.decode(str,pos+1,bpos-1,TRUE)
NEW f.create(self.precision)
k[2]:=f
pos:=bpos
bpos:=end
f.decode(str,pos+1,bpos-1,TRUE)
ELSEIF StrCmp(tstr,'g',1)
self.type:=farray[FTYPE_Green]
NEW k[3]
self.args:=k
pos:=findcomma(str,start+2)
IF pos=-1
NEW f.create(self.precision)
k[1]:=f
NEW f.create(self.precision)
k[2]:=f
Raise(-1)
ENDIF
k[]:=gtd(dat,Val(str+start+2))
NEW f.create(self.precision)
k[1]:=f
bpos:=findcomma(str,pos+1)
IF (bpos=-1) OR (k[]=0)
NEW f.create(self.precision)
k[2]:=f
Raise(-1)
ENDIF
f.decode(str,pos+1,bpos-1,TRUE)
NEW f.create(self.precision)
k[2]:=f
pos:=bpos
bpos:=end
f.decode(str,pos+1,bpos-1,TRUE)
ELSEIF StrCmp(tstr,'b',1)
self.type:=farray[FTYPE_Blue]
NEW k[3]
self.args:=k
pos:=findcomma(str,start+2)
IF pos=-1
NEW f.create(self.precision)
k[1]:=f
NEW f.create(self.precision)
k[2]:=f
Raise(-1)
ENDIF
k[]:=gtd(dat,Val(str+start+2))
NEW f.create(self.precision)
k[1]:=f
bpos:=findcomma(str,pos+1)
IF (bpos=-1) OR (k[]=0)
NEW f.create(self.precision)
k[2]:=f
Raise(-1)
ENDIF
f.decode(str,pos+1,bpos-1,TRUE)
NEW f.create(self.precision)
k[2]:=f
pos:=bpos
bpos:=end
f.decode(str,pos+1,bpos-1,TRUE)
ELSEIF StrCmp(tstr,'mod',3)
self.type:=farray[FTYPE_Mod]
NEW k[2]
self.args:=k
NEW f.create(self.precision)
self.args[]:=f
pos:=findcomma(str,start+4)
IF pos = -1
NEW f.create(self.precision)
self.args[1]:=f
Raise(-1)
ENDIF
f.decode(str,start+4,pos-1,TRUE)
self.constant:=f.constant
NEW f.create(self.precision)
self.args[1]:=f
f.decode(str,pos+1,end-1,TRUE)
self.constant:=self.constant AND f.constant
ELSEIF StrCmp(tstr,'min',3)
self.type:=farray[FTYPE_Min]
NEW k[2]
self.args:=k
NEW f.create(self.precision)
self.args[]:=f
pos:=findcomma(str,start+4)
IF pos = -1
NEW f.create(self.precision)
self.args[1]:=f
Raise(-1)
ENDIF
f.decode(str,start+4,pos-1,TRUE)
self.constant:=f.constant
NEW f.create(self.precision)
self.args[1]:=f
f.decode(str,pos+1,end-1,TRUE)
self.constant:=self.constant AND f.constant
ELSEIF StrCmp(tstr,'max',3)
self.type:=farray[FTYPE_Max]
NEW k[2]
self.args:=k
NEW f.create(self.precision)
self.args[]:=f
pos:=findcomma(str,start+4)
IF pos = -1
NEW f.create(self.precision)
self.args[1]:=f
Raise(-1)
ENDIF
f.decode(str,start+4,pos-1,TRUE)
self.constant:=f.constant
NEW f.create(self.precision)
self.args[1]:=f
f.decode(str,pos+1,end-1,TRUE)
self.constant:=self.constant AND f.constant
ELSEIF StrCmp(tstr,'asin',4)
self.type:=farray[FTYPE_ASin]
NEW f.create(self.precision)
self.args:=f
f.decode(str,start+5,end-1,TRUE)
self.constant:=f.constant
ELSEIF StrCmp(tstr,'acos',4)
self.type:=farray[FTYPE_ACos]
NEW f.create(self.precision)
self.args:=f
f.decode(str,start+5,end-1,TRUE)
self.constant:=f.constant
ELSEIF StrCmp(tstr,'atan',4)
self.type:=farray[FTYPE_ATan]
NEW f.create(self.precision)
self.args:=f
f.decode(str,start+5,end-1,TRUE)
self.constant:=f.constant
ELSEIF StrCmp(tstr,'sin',3)
self.type:=farray[FTYPE_Sin]
NEW f.create(self.precision)
self.args:=f
f.decode(str,start+4,end-1,TRUE)
self.constant:=f.constant
ELSEIF StrCmp(tstr,'cos',3)
self.type:=farray[FTYPE_Cos]
NEW f.create(self.precision)
self.args:=f
f.decode(str,start+4,end-1,TRUE)
self.constant:=f.constant
ELSEIF StrCmp(tstr,'tan',3)
self.type:=farray[FTYPE_Tan]
NEW f.create(self.precision)
self.args:=f
f.decode(str,start+4,end-1,TRUE)
self.constant:=f.constant
ELSEIF tstr[]="("
self.decode(str,start+1,end-1,modl) -> just decode what is within the brackets
ELSE
self.type:=farray[FTYPE_Constant]
IF (tstr[] < "0") OR (tstr[] > "9") THEN Raise(-1)
self.constant:=TRUE
IF self.precision=OUT_Integer
self.args:=Val(tstr)
self.value:=self.args
ELSEIF self.precision=OUT_Float32
self.args:=RealVal(tstr)
self.value:=self.args
ELSEIF self.precision=OUT_Float64
NEW lr
self.args:=lr
a2d(tstr,lr)
dCopy(self.value,self.args)
ENDIF
ENDIF
DisposeLink(tstr)
ELSE
self.type:=farray[btype]
NEW k[2]
self.args := k
NEW f.create(self.precision)
self.args[0]:=f
f.decode(str,start,bpos-1,TRUE)
self.constant:=f.constant
NEW f.create(self.precision)
self.args[1]:=f
f.decode(str,bpos+1,end,TRUE)
self.constant:=self.constant AND f.constant -> only if both args are constant, self will be constant.
ENDIF
EXCEPT
self.end()
IF modl -> Another .decode() called us, so call it's Exception handler
Raise(-1)
ELSE -> this .decode() has been called from picFX. don't call it's Exception handler but return TRUE.
RETURN TRUE
ENDIF
ENDPROC FALSE
PROC priority(type)
IF type <= FTYPE_Substr; RETURN 1 /* + - : 1 */
ELSEIF type <= FTYPE_Divide; RETURN 2 /* * / : 2 */
ELSEIF type = FTYPE_Power; RETURN 3 /* ^ : 3 */
ELSE ; RETURN 4
ENDIF
ENDPROC
PROC sep(str:PTR TO CHAR,start)
DEF q,r,f,p
p:=InStr(str,'(',start)
r:=StrLen(str)
IF p=-1 THEN p:=r+1
IF (q:=InStr(str,'+',start)) <> -1
r:=q;f:=FTYPE_Plus
ENDIF
IF ((q:=InStr(str,'-',start)) <> -1) AND (q < r)
r:=q;f:=FTYPE_Substr
ENDIF
IF ((q:=InStr(str,'*',start)) <> -1) AND (q < r)
r:=q;f:=FTYPE_Multiply
ENDIF
IF ((q:=InStr(str,'/',start)) <> -1) AND (q < r)
r:=q;f:=FTYPE_Divide
ENDIF
IF ((q:=InStr(str,'^',start)) <> -1) AND (q < r)
r:=q;f:=FTYPE_Power
ENDIF
IF r > p THEN r,f:=sep(str,findclose(str,p))
ENDPROC r,f
PROC findclose(str:PTR TO CHAR,open)
DEF a,b
a:=InStr(str,'(',open+1) /*a is the first ( */
IF a=-1 THEN a:=StrLen(str)
b:=InStr(str,')',open+1) /*b is the first ) */
IF b=-1 THEN Raise(-1)
IF b < a THEN RETURN b /*If the first ) is before the first ( , then return the former*/
b:=findclose(str,a) /*else: first find when the first ( closes...*/
RETURN findclose(str,b) /*...and then search for the next )*/
ENDPROC
PROC findcomma(str:PTR TO CHAR,start)
DEF a,b
a:=InStr(str,',',start+1)
b:=InStr(str,'(',start+1)
IF (b = -1) OR (b > a) THEN -> No parhenthesis bothering before that comma
RETURN a
ENDPROC findcomma(str,findclose(str,b))
PROC reference() OF function
IF (self.type=farray[FTYPE_Red]) OR
(self.type=farray[FTYPE_Green]) OR
(self.type=farray[FTYPE_Blue]) THEN
RETURN self.args[0],self.args[1],self.args[2]
IF self.type <= farray[FTYPE_Variable] THEN
RETURN 1,NIL,NIL
IF self.type <= farray[FTYPE_Min] THEN
RETURN 3,self.args[0],self.args[1]
ENDPROC 2,self.args,NIL
/*for constant and variables, no precalculation is done..*/
PROC enone(x,y,lr:PTR TO longreal,fnc:PTR TO function)
IF fnc.precision=OUT_Integer ;RETURN 0
ELSEIF fnc.precision=OUT_Float32;RETURN 0.
ELSEIF fnc.precision=OUT_Float64;RETURN dFloat(0,lr)
ENDIF
ENDPROC
PROC econst(x,y,lr:PTR TO longreal,fnc:PTR TO function)
IF fnc.precision=OUT_Float64
dCopy(lr,fnc.args)
RETURN lr
ENDIF
ENDPROC fnc.args
PROC evar(x,y,lr:PTR TO longreal,fnc:PTR TO function)
DEF type
type:= fnc.args
IF fnc.precision=OUT_Integer
SELECT type
CASE VAR_x;RETURN x
CASE VAR_y;RETURN y
CASE CTE_e;RETURN 3 /*quite inaccurate... ;-)*/
CASE CTE_pi;RETURN 3
ENDSELECT
ELSEIF fnc.precision=OUT_Float32
SELECT type
CASE VAR_x;RETURN x!
CASE VAR_y;RETURN y!
CASE CTE_e;RETURN 2.71828183
CASE CTE_pi;RETURN 3.14159265
ENDSELECT
ELSEIF fnc.precision=OUT_Float64
SELECT type
CASE VAR_x;RETURN dFloat(x,lr)
CASE VAR_y;RETURN dFloat(y,lr)
CASE CTE_e;RETURN a2d('2.71828182846',lr)
CASE CTE_pi;RETURN dPi(lr)
ENDSELECT
ENDIF
ENDPROC
PROC eplus(x,y,lr:PTR TO longreal,fnc:PTR TO function)
DEF f1:PTR TO function,f2:PTR TO function,lrl:PTR TO longreal
DEF p1,p2
IF fnc.constant /*either return precalculated value or calculate it*/
IF x<>TRUE
IF fnc.precision=OUT_Float64 THEN
RETURN dCopy(lr,fnc.value)
RETURN fnc.value
ENDIF
f1:=fnc.args[];f2:=fnc.args[1]
p1:=f1.type;p2:=f2.type
IF fnc.precision=OUT_Integer
fnc.value:= p1(x,y,lr,f1) + p2(x,y,lr,f2)
RETURN fnc.value
ELSEIF fnc.precision=OUT_Float32
fnc.value:= !p1(x,y,lr,f1)+p2(x,y,lr,f2)
RETURN fnc.value
ELSEIF fnc.precision=OUT_Float64
NEW lrl
dAdd(p1(x,y,lr,f1),p2(x,y,lrl,f2)) -> result put in lr
END lrl
RETURN dCopy(fnc.value,lr)
ENDIF
ELSE /*no precalculation involved*/
f1:=fnc.args[];f2:=fnc.args[1]
p1:=f1.type;p2:=f2.type
IF fnc.precision=OUT_Integer
RETURN p1(x,y,lr,f1) + p2(x,y,lr,f2)
ELSEIF fnc.precision=OUT_Float32
RETURN !p1(x,y,lr,f1)+p2(x,y,lr,f2)
ELSEIF fnc.precision=OUT_Float64
NEW lrl
dAdd(p1(x,y,lr,f1),p2(x,y,lrl,f2)) -> result put in lr
END lrl
RETURN lr
ENDIF
ENDIF
ENDPROC
PROC esubstr(x,y,lr:PTR TO longreal,fnc:PTR TO function)
DEF f1:PTR TO function,f2:PTR TO function,lrl:PTR TO longreal
DEF p1,p2
IF fnc.constant
IF x<>TRUE
IF fnc.precision=OUT_Float64 THEN
RETURN dCopy(lr,fnc.value)
RETURN fnc.value
ENDIF
f1:=fnc.args[];f2:=fnc.args[1]
p1:=f1.type;p2:=f2.type
IF fnc.precision=OUT_Integer
fnc.value:= p1(x,y,lr,f1) - p2(x,y,lr,f2)
RETURN fnc.value
ELSEIF fnc.precision=OUT_Float32
fnc.value:= !p1(x,y,lr,f1) - p2(x,y,lr,f2)
RETURN fnc.value
ELSEIF fnc.precision=OUT_Float64
NEW lrl
dSub(p1(x,y,lr,f1),p2(x,y,lrl,f2)) -> result put in lr
END lrl
RETURN dCopy(fnc.value,lr)
ENDIF
ELSE
f1:=fnc.args[];f2:=fnc.args[1]
p1:=f1.type;p2:=f2.type
IF fnc.precision=OUT_Integer
RETURN p1(x,y,lr,f1) - p2(x,y,lr,f2)
ELSEIF fnc.precision=OUT_Float32
RETURN !p1(x,y,lr,f1) - p2(x,y,lr,f2)
ELSEIF fnc.precision=OUT_Float64
NEW lrl
dSub(p1(x,y,lr,f1),p2(x,y,lrl,f2)) -> result put in lr
END lrl
RETURN lr
ENDIF
ENDIF
ENDPROC
PROC emultiply(x,y,lr:PTR TO longreal,fnc:PTR TO function)
DEF f1:PTR TO function,f2:PTR TO function,lrl:PTR TO longreal
DEF p1,p2
IF fnc.constant
IF x<>TRUE
IF fnc.precision=OUT_Float64 THEN
RETURN dCopy(lr,fnc.value)
RETURN fnc.value
ENDIF
f1:=fnc.args[];f2:=fnc.args[1]
p1:=f1.type;p2:=f2.type
IF fnc.precision=OUT_Integer
fnc.value:= Mul(p1(x,y,lr,f1) , p2(x,y,lr,f2))
RETURN fnc.value
ELSEIF fnc.precision=OUT_Float32
fnc.value:= !p1(x,y,lr,f1) * p2(x,y,lr,f2)
RETURN fnc.value
ELSEIF fnc.precision=OUT_Float64
NEW lrl
dMul(p1(x,y,lr,f1),p2(x,y,lrl,f2))
END lrl
RETURN dCopy(fnc.value,lr)
ENDIF
ELSE
f1:=fnc.args[];f2:=fnc.args[1]
p1:=f1.type;p2:=f2.type
IF fnc.precision=OUT_Integer
RETURN Mul(p1(x,y,lr,f1) , p2(x,y,lr,f2))
ELSEIF fnc.precision=OUT_Float32
RETURN !p1(x,y,lr,f1) * p2(x,y,lr,f2)
ELSEIF fnc.precision=OUT_Float64
NEW lrl
dMul(p1(x,y,lr,f1),p2(x,y,lrl,f2))
END lrl
RETURN lr
ENDIF
ENDIF
ENDPROC
PROC edivide(x,y,lr:PTR TO longreal,fnc:PTR TO function)
DEF f1:PTR TO function,f2:PTR TO function,lrl:PTR TO longreal,k
DEF p1,p2
IF fnc.constant
IF x<>TRUE
IF fnc.precision=OUT_Float64
dCopy(lr,fnc.value);RETURN lr
ENDIF
RETURN fnc.value
ENDIF
f1:=fnc.args[];f2:=fnc.args[1]
p1:=f1.type;p2:=f2.type
IF fnc.precision=OUT_Integer
k:=p2(x,y,lr,f2)
IF k = 0
fnc.value:=-123456
RETURN fnc.value
ENDIF
fnc.value:= Div(p1(x,y,lr,f1) , k)
RETURN fnc.value
ELSEIF fnc.precision=OUT_Float32
k:=p2(x,y,lr,f2)
IF !k! = 0
fnc.value:=-123456
RETURN fnc.value
ENDIF
fnc.value:=!p1(x,y,lr,f1) / k
RETURN fnc.value
ELSEIF fnc.precision=OUT_Float64
NEW lrl
p2(x,y,lrl,f2)
IF dCompare(dFloat(0,lr),lrl)=0
END lrl
dFloat(-123456,lr)
RETURN lr
ENDIF
dDiv(p1(x,y,lr,f1),lrl)
END lrl
dCopy(fnc.value,lr)
RETURN lr
ENDIF
ELSE
f1:=fnc.args[];f2:=fnc.args[1]
p1:=f1.type;p2:=f2.type
IF fnc.precision=OUT_Integer
k:=p2(x,y,lr,f2)
IF k = 0 THEN RETURN -123456
RETURN Div(p1(x,y,lr,f1) , k)
ELSEIF fnc.precision=OUT_Float32
k:=p2(x,y,lr,f2)
IF !k! = 0 THEN RETURN -123456
RETURN !p1(x,y,lr,f1) / k
ELSEIF fnc.precision=OUT_Float64
NEW lrl
lrl:=p2(x,y,lrl,f2)
IF dCompare(dFloat(0,lr),lrl)=0
END lrl
dFloat(-123456,lr)
RETURN lr
ENDIF
dDiv(p1(x,y,lr,f1),lrl)
END lrl
RETURN lr
ENDIF
ENDIF
ENDPROC
PROC epower(x,y,lr:PTR TO longreal,fnc:PTR TO function)
DEF f1:PTR TO function,f2:PTR TO function,lrl:PTR TO longreal
DEF p1,p2
IF fnc.constant
IF x<>TRUE
IF fnc.precision=OUT_Float64
dCopy(lr,fnc.value);RETURN lr
ENDIF
RETURN fnc.value
ENDIF
f1:=fnc.args[];f2:=fnc.args[1]
p1:=f1.type;p2:=f2.type
IF fnc.precision=OUT_Integer
fnc.value:= power(p1(x,y,lr,f1) , p2(x,y,lr,f2))
RETURN fnc.value
ELSEIF fnc.precision=OUT_Float32
fnc.value:= Fpow(p2(x,y,lr,f2) , p1(x,y,lr,f1))
RETURN fnc.value
ELSEIF fnc.precision=OUT_Float64
NEW lrl
dPow(p1(x,y,lr,f1),p2(x,y,lrl,f2))
END lrl
dCopy(fnc.value,lr)
RETURN lr
ENDIF
ELSE
f1:=fnc.args[];f2:=fnc.args[1]
p1:=f1.type;p2:=f2.type
IF fnc.precision=OUT_Integer
RETURN power(p1(x,y,lr,f1) , p2(x,y,lr,f2))
ELSEIF fnc.precision=OUT_Float32
RETURN Fpow(p2(x,y,lr,f2) , p1(x,y,lr,f1)) /*Hmm, Fpow(a,b) is b^a..*/
ELSEIF fnc.precision=OUT_Float64
NEW lrl
dPow(p1(x,y,lr,f1),p2(x,y,lrl,f2))
END lrl
RETURN lr
ENDIF
ENDIF
ENDPROC
PROC emod(x,y,lr:PTR TO longreal,fnc:PTR TO function)
DEF f1:PTR TO function,f2:PTR TO function,lrl:PTR TO longreal
DEF p1,p2
IF fnc.constant
IF x<>TRUE
IF fnc.precision=OUT_Float64 THEN
RETURN dCopy(lr,fnc.value)
RETURN fnc.value
ENDIF
f1:=fnc.args[];f2:=fnc.args[1]
p1:=f1.type;p2:=f2.type
IF fnc.precision=OUT_Integer
lrl:=p2(x,y,lr,f2)
IF lrl > 0
fnc.value:= Mod(p1(x,y,lr,f1) , lrl)
ELSE
fnc.value:= 0
ENDIF
RETURN fnc.value
ELSEIF fnc.precision=OUT_Float32
fnc.value:= fMod(p1(x,y,lr,f1) , p2(x,y,lr,f2))
RETURN fnc.value
ELSEIF fnc.precision=OUT_Float64
/*Pff.*/
RETURN dFloat(0,lr)
ENDIF
ELSE /*no precalculation involved*/
f1:=fnc.args[];f2:=fnc.args[1]
p1:=f1.type;p2:=f2.type
IF fnc.precision=OUT_Integer
lrl:=p2(x,y,lr,f2)
IF lrl > 0
RETURN Mod(p1(x,y,lr,f1) , lrl)
ELSE
RETURN 0
ENDIF
ELSEIF fnc.precision=OUT_Float32
RETURN fMod(p1(x,y,lr,f1) , p2(x,y,lr,f2))
ELSEIF fnc.precision=OUT_Float64
RETURN dFloat(0,lr)
ENDIF
ENDIF
ENDPROC
PROC fMod(a,b) IS !a-(!Ffloor(!a/b)*b)
PROC emax(x,y,lr:PTR TO longreal,fnc:PTR TO function)
DEF f1:PTR TO function,f2:PTR TO function,lrl:PTR TO longreal
DEF p1,p2
IF fnc.constant
IF x<>TRUE
IF fnc.precision=OUT_Float64 THEN
RETURN dCopy(lr,fnc.value)
RETURN fnc.value
ENDIF
f1:=fnc.args[];f2:=fnc.args[1]
p1:=f1.type;p2:=f2.type
IF fnc.precision=OUT_Integer
fnc.value:= Max(p1(x,y,lr,f1) , p2(x,y,lr,f2))
RETURN fnc.value
ELSEIF fnc.precision=OUT_Float32
fnc.value:= fMax(p1(x,y,lr,f1) , p2(x,y,lr,f2))
RETURN fnc.value
ELSEIF fnc.precision=OUT_Float64
NEW lrl
dCopy(fnc.value,dMax(p1(x,y,lr,f1) , p2(x,y,lrl,f2)))
END lrl
RETURN dCopy(fnc.value,lr)
ENDIF
ELSE
f1:=fnc.args[];f2:=fnc.args[1]
p1:=f1.type;p2:=f2.type
IF fnc.precision=OUT_Integer
RETURN Max(p1(x,y,lr,f1) , p2(x,y,lr,f2))
ELSEIF fnc.precision=OUT_Float32
RETURN fMax(p1(x,y,lr,f1) , p2(x,y,lr,f2))
ELSEIF fnc.precision=OUT_Float64
NEW lrl
dCopy(lr,dMax(p1(x,y,lr,f1) , p2(x,y,lrl,f2)))
END lrl
RETURN lr
ENDIF
ENDIF
ENDPROC
PROC fMax(a,b)
IF !a<b THEN RETURN b ELSE RETURN a
ENDPROC
PROC dMax(a,b)
IF dCompare(a,b)=-1 THEN RETURN b ELSE RETURN a
ENDPROC
PROC emin(x,y,lr:PTR TO longreal,fnc:PTR TO function)
DEF f1:PTR TO function,f2:PTR TO function,lrl:PTR TO longreal
DEF p1,p2
IF fnc.constant
IF x<>TRUE
IF fnc.precision=OUT_Float64 THEN
RETURN dCopy(lr,fnc.value)
RETURN fnc.value
ENDIF
f1:=fnc.args[];f2:=fnc.args[1]
p1:=f1.type;p2:=f2.type
IF fnc.precision=OUT_Integer
fnc.value:= Min(p1(x,y,lr,f1) , p2(x,y,lr,f2))
RETURN fnc.value
ELSEIF fnc.precision=OUT_Float32
fnc.value:= fMin(p1(x,y,lr,f1) , p2(x,y,lr,f2))
RETURN fnc.value
ELSEIF fnc.precision=OUT_Float64
NEW lrl
dCopy(fnc.value,dMin(p1(x,y,lr,f1) , p2(x,y,lrl,f2)))
END lrl
RETURN dCopy(fnc.value,lr)
ENDIF
ELSE
f1:=fnc.args[];f2:=fnc.args[1]
p1:=f1.type;p2:=f2.type
IF fnc.precision=OUT_Integer
RETURN Min(p1(x,y,lr,f1) , p2(x,y,lr,f2))
ELSEIF fnc.precision=OUT_Float32
RETURN fMin(p1(x,y,lr,f1) , p2(x,y,lr,f2))
ELSEIF fnc.precision=OUT_Float64
NEW lrl
dCopy(lr,dMin(p1(x,y,lr,f1) , p2(x,y,lrl,f2)))
END lrl
RETURN lr
ENDIF
ENDIF
ENDPROC
PROC fMin(a,b)
IF !a>b THEN RETURN b ELSE RETURN a
ENDPROC
PROC dMin(a,b)
IF dCompare(a,b)=1 THEN RETURN b ELSE RETURN a
ENDPROC
PROC esin(x,y,lr:PTR TO longreal,fnc:PTR TO function)
DEF f1:PTR TO function
DEF p1
IF fnc.constant
IF x<>TRUE
IF fnc.precision=OUT_Float64
dCopy(lr,fnc.value);RETURN lr
ENDIF
RETURN fnc.value
ENDIF
f1:=fnc.args
p1:=f1.type
IF fnc.precision=OUT_Integer
fnc.value:=0;RETURN 0 -> (Would be quite silly to compute trig functions with integers)
ELSEIF fnc.precision=OUT_Float32
fnc.value:=Fsin(p1(x,y,lr,f1))
RETURN fnc.value
ELSEIF fnc.precision=OUT_Float64
dSin(p1(x,y,lr,f1))
dCopy(fnc.value,lr)
RETURN lr
ENDIF
ELSE
f1:=fnc.args
p1:=f1.type
IF fnc.precision=OUT_Integer;RETURN 0
ELSEIF fnc.precision=OUT_Float32
RETURN Fsin(p1(x,y,lr,f1))
ELSEIF fnc.precision=OUT_Float64
RETURN dSin(p1(x,y,lr,f1))
ENDIF
ENDIF
ENDPROC
PROC ecos(x,y,lr:PTR TO longreal,fnc:PTR TO function)
DEF f1:PTR TO function
DEF p1
IF fnc.constant
IF x<>TRUE
IF fnc.precision=OUT_Float64
dCopy(lr,fnc.value);RETURN lr
ENDIF
RETURN fnc.value
ENDIF
f1:=fnc.args
p1:=f1.type
IF fnc.precision=OUT_Integer
fnc.value:=0;RETURN 0
ELSEIF fnc.precision=OUT_Float32
fnc.value:= Fcos(p1(x,y,lr,f1))
RETURN fnc.value
ELSEIF fnc.precision=OUT_Float64
dCos(p1(x,y,lr,f1))
dCopy(fnc.value,lr)
RETURN lr
ENDIF
ELSE
f1:=fnc.args
p1:=f1.type
IF fnc.precision=OUT_Integer;RETURN 0
ELSEIF fnc.precision=OUT_Float32
RETURN Fcos(p1(x,y,lr,f1))
ELSEIF fnc.precision=OUT_Float64
RETURN dCos(p1(x,y,lr,f1))
ENDIF
ENDIF
ENDPROC
PROC etan(x,y,lr:PTR TO longreal,fnc:PTR TO function)
DEF f1:PTR TO function
DEF p1
IF fnc.constant
IF x<>TRUE
IF fnc.precision=OUT_Float64
dCopy(lr,fnc.value);RETURN lr
ENDIF
RETURN fnc.value
ENDIF
f1:=fnc.args
p1:=f1.type
IF fnc.precision=OUT_Integer
fnc.value:=0;RETURN 0
ELSEIF fnc.precision=OUT_Float32
fnc.value:= Ftan(p1(x,y,lr,f1))
RETURN fnc.value
ELSEIF fnc.precision=OUT_Float64
dTan(p1(x,y,lr,f1))
dCopy(fnc.value,lr)
RETURN lr
ENDIF
ELSE
f1:=fnc.args
p1:=f1.type
IF fnc.precision=OUT_Integer;RETURN 0
ELSEIF fnc.precision=OUT_Float32
RETURN Ftan(p1(x,y,lr,f1))
ELSEIF fnc.precision=OUT_Float64
RETURN dTan(p1(x,y,lr,f1))
ENDIF
ENDIF
ENDPROC
PROC easin(x,y,lr:PTR TO longreal,fnc:PTR TO function)
DEF f1:PTR TO function
DEF p1
IF fnc.constant
IF x<>TRUE
IF fnc.precision=OUT_Float64
dCopy(lr,fnc.value);RETURN lr
ENDIF
RETURN fnc.value
ENDIF
f1:=fnc.args
p1:=f1.type
IF fnc.precision=OUT_Integer
fnc.value:=0;RETURN 0
ELSEIF fnc.precision=OUT_Float32
fnc.value:= Fasin(p1(x,y,lr,f1))
RETURN fnc.value
ELSEIF fnc.precision=OUT_Float64
dASin(p1(x,y,lr,f1))
dCopy(fnc.value,lr)
RETURN lr
ENDIF
ELSE
f1:=fnc.args
p1:=f1.type
IF fnc.precision=OUT_Integer;RETURN 0
ELSEIF fnc.precision=OUT_Float32
RETURN Fasin(p1(x,y,lr,f1))
ELSEIF fnc.precision=OUT_Float64
RETURN dASin(p1(x,y,lr,f1))
ENDIF
ENDIF
ENDPROC
PROC eacos(x,y,lr:PTR TO longreal,fnc:PTR TO function)
DEF f1:PTR TO function
DEF p1
IF fnc.constant
IF x<>TRUE
IF fnc.precision=OUT_Float64
dCopy(lr,fnc.value);RETURN lr
ENDIF
RETURN fnc.value
ENDIF
f1:=fnc.args
p1:=f1.type
IF fnc.precision=OUT_Integer
fnc.value:=0;RETURN 0
ELSEIF fnc.precision=OUT_Float32
fnc.value:= Facos(p1(x,y,lr,f1))
RETURN fnc.value
ELSEIF fnc.precision=OUT_Float64
dACos(p1(x,y,lr,f1))
dCopy(fnc.value,lr)
RETURN lr
ENDIF
ELSE
f1:=fnc.args
p1:=f1.type
IF fnc.precision=OUT_Integer;RETURN 0
ELSEIF fnc.precision=OUT_Float32
RETURN Facos(p1(x,y,lr,f1))
ELSEIF fnc.precision=OUT_Float64
RETURN dACos(p1(x,y,lr,f1))
ENDIF
ENDIF
ENDPROC
PROC eatan(x,y,lr:PTR TO longreal,fnc:PTR TO function)
DEF f1:PTR TO function
DEF p1
IF fnc.constant
IF x<>TRUE
IF fnc.precision=OUT_Float64
dCopy(lr,fnc.value);RETURN lr
ENDIF
RETURN fnc.value
ENDIF
f1:=fnc.args
p1:=f1.type
IF fnc.precision=OUT_Integer
fnc.value:=0;RETURN 0
ELSEIF fnc.precision=OUT_Float32
fnc.value:= Fatan(p1(x,y,lr,f1))
RETURN fnc.value
ELSEIF fnc.precision=OUT_Float64
dATan(p1(x,y,lr,f1))
dCopy(fnc.value,lr)
RETURN lr
ENDIF
ELSE
f1:=fnc.args
p1:=f1.type
IF fnc.precision=OUT_Integer;RETURN 0
ELSEIF fnc.precision=OUT_Float32
RETURN Fatan(p1(x,y,lr,f1))
ELSEIF fnc.precision=OUT_Float64
RETURN dATan(p1(x,y,lr,f1))
ENDIF
ENDIF
ENDPROC
EXPORT PROC kmod(a,b)
IF a >= 0 THEN RETURN Mod(a,b)
ENDPROC Mod(a,b)+b
PROC ered(x,y,lr:PTR TO longreal,fnc:PTR TO function)
DEF f1:PTR TO function,f2:PTR TO function,lrl:PTR TO longreal
DEF p1,p2,xx,yy,data:PTR TO planeFunc_data
f1:=fnc.args[1];f2:=fnc.args[2]
p1:=f1.type; p2:=f2.type
xx:=p1(x,y,lr,f1)
IF fnc.precision=OUT_Float64 THEN
NEW lrl
yy:=p2(x,y,lrl,f2)
data:=fnc.args[]
IF fnc.precision=OUT_Integer
RETURN Shr(ReadRGBPixel(data.rp,kmod(xx,data.width),kmod(yy,data.height)),16)
ELSEIF fnc.precision=OUT_Float32
RETURN Shr(ReadRGBPixel(data.rp,kmod(!xx!,data.width),kmod(!yy!,data.height)),16)!
ELSEIF fnc.precision=OUT_Float64
xx:=Shr(ReadRGBPixel(data.rp,kmod(dFix(lr),data.width),kmod(dFix(lrl),data.height)),16)
END lrl
RETURN dFloat(xx,lr)
ENDIF
ENDPROC
PROC egreen(x,y,lr:PTR TO longreal,fnc:PTR TO function)
DEF f1:PTR TO function,f2:PTR TO function,lrl:PTR TO longreal
DEF p1,p2,xx,yy,data:PTR TO planeFunc_data
f1:=fnc.args[1];f2:=fnc.args[2]
p1:=f1.type; p2:=f2.type
xx:=p1(x,y,lr,f1)
IF fnc.precision=OUT_Float64 THEN
NEW lrl
yy:=p2(x,y,lrl,f2)
data:=fnc.args[]
IF fnc.precision=OUT_Integer
RETURN Shr(ReadRGBPixel(data.rp,kmod(xx,data.width),kmod(yy,data.height)) AND $FF00,8)
ELSEIF fnc.precision=OUT_Float32
RETURN Shr(ReadRGBPixel(data.rp,kmod(!xx!,data.width),kmod(!yy!,data.height)) AND $FF00,8)!
ELSEIF fnc.precision=OUT_Float64
xx:=Shr(ReadRGBPixel(data.rp,kmod(dFix(lr),data.width),kmod(dFix(lrl),data.height)) AND $FF00,8)
END lrl
RETURN dFloat(xx,lr)
ENDIF
ENDPROC
PROC eblue(x,y,lr:PTR TO longreal,fnc:PTR TO function)
DEF f1:PTR TO function,f2:PTR TO function,lrl:PTR TO longreal
DEF p1,p2,xx,yy,data:PTR TO planeFunc_data
f1:=fnc.args[1];f2:=fnc.args[2]
p1:=f1.type; p2:=f2.type
xx:=p1(x,y,lr,f1)
IF fnc.precision=OUT_Float64 THEN
NEW lrl
yy:=p2(x,y,lrl,f2)
data:=fnc.args[]
IF fnc.precision=OUT_Integer
RETURN ReadRGBPixel(data.rp,kmod(xx,data.width),kmod(yy,data.height)) AND $FF
ELSEIF fnc.precision=OUT_Float32
RETURN (ReadRGBPixel(data.rp,kmod(!xx!,data.width),kmod(!yy!,data.height)) AND $FF)!
ELSEIF fnc.precision=OUT_Float64
xx:=ReadRGBPixel(data.rp,kmod(dFix(lr),data.width),kmod(dFix(lrl),data.height)) AND $FF
END lrl
RETURN dFloat(xx,lr)
ENDIF
ENDPROC
/*Picasso 96 version of Inter-Referencing functions... */
PROC pred(x,y,lr:PTR TO longreal,fnc:PTR TO function)
DEF f1:PTR TO function,f2:PTR TO function,lrl:PTR TO longreal
DEF p1,p2,xx,yy,data:PTR TO planeFunc_data
f1:=fnc.args[1];f2:=fnc.args[2]
p1:=f1.type; p2:=f2.type
xx:=p1(x,y,lr,f1)
IF fnc.precision=OUT_Float64 THEN
NEW lrl
yy:=p2(x,y,lrl,f2)
data:=fnc.args[]
IF fnc.precision=OUT_Integer
p1:=Pi96ReadPixel(data.rp,kmod(xx,data.width),kmod(yy,data.height))
RETURN Shr(p1,16)
ELSEIF fnc.precision=OUT_Float32
RETURN Shr(Pi96ReadPixel(data.rp,kmod(!xx!,data.width),kmod(!yy!,data.height)),16)!
ELSEIF fnc.precision=OUT_Float64
xx:=Shr(Pi96ReadPixel(data.rp,kmod(dFix(lr),data.width),kmod(dFix(lrl),data.height)),16)
END lrl
RETURN dFloat(xx,lr)
ENDIF
ENDPROC
PROC pgreen(x,y,lr:PTR TO longreal,fnc:PTR TO function)
DEF f1:PTR TO function,f2:PTR TO function,lrl:PTR TO longreal
DEF p1,p2,xx,yy,data:PTR TO planeFunc_data
f1:=fnc.args[1];f2:=fnc.args[2]
p1:=f1.type; p2:=f2.type
xx:=p1(x,y,lr,f1)
IF fnc.precision=OUT_Float64 THEN
NEW lrl
yy:=p2(x,y,lrl,f2)
data:=fnc.args[]
IF fnc.precision=OUT_Integer
RETURN Shr(Pi96ReadPixel(data.rp,kmod(xx,data.width),kmod(yy,data.height)) AND $FF00,8)
ELSEIF fnc.precision=OUT_Float32
RETURN Shr(Pi96ReadPixel(data.rp,kmod(!xx!,data.width),kmod(!yy!,data.height)) AND $FF00,8)!
ELSEIF fnc.precision=OUT_Float64
xx:=Shr(Pi96ReadPixel(data.rp,kmod(dFix(lr),data.width),kmod(dFix(lrl),data.height)) AND $FF00,8)
END lrl
RETURN dFloat(xx,lr)
ENDIF
ENDPROC
PROC pblue(x,y,lr:PTR TO longreal,fnc:PTR TO function)
DEF f1:PTR TO function,f2:PTR TO function,lrl:PTR TO longreal
DEF p1,p2,xx,yy,data:PTR TO planeFunc_data
f1:=fnc.args[1];f2:=fnc.args[2]
p1:=f1.type; p2:=f2.type
xx:=p1(x,y,lr,f1)
IF fnc.precision=OUT_Float64 THEN
NEW lrl
yy:=p2(x,y,lrl,f2)
data:=fnc.args[]
IF fnc.precision=OUT_Integer
RETURN Pi96ReadPixel(data.rp,kmod(xx,data.width),kmod(yy,data.height)) AND $FF
ELSEIF fnc.precision=OUT_Float32
RETURN (Pi96ReadPixel(data.rp,kmod(!xx!,data.width),kmod(!yy!,data.height)) AND $FF)!
ELSEIF fnc.precision=OUT_Float64
xx:=Pi96ReadPixel(data.rp,kmod(dFix(lr),data.width),kmod(dFix(lrl),data.height)) AND $FF
END lrl
RETURN dFloat(xx,lr)
ENDIF
ENDPROC
PROC power(base,exp)
DEF result
IF exp = 0 THEN RETURN 1
result:=base
WHILE exp > 1
result:=Mul(result,base)
exp--
ENDWHILE
ENDPROC result
PROC create(precision) OF function
DEF lr:PTR TO longreal
self.precision:=precision
self.type:=farray[FTYPE_None]
IF precision=OUT_Float64
NEW lr
self.value:=lr
dFloat(0,lr)
ENDIF
ENDPROC 1
PROC proc() OF function IS self.type /* a method and no direct access, so that
the user can only read the attribute... */
PROC end() OF function
DEF k:PTR TO LONG,lr:PTR TO longreal
IF self.precision=OUT_Float64 AND (self.nofree=FALSE)
lr:=self.value
END lr
IF self.type=farray[FTYPE_Constant]
lr:=self.args
END lr
ENDIF
ENDIF
IF self.type <= farray[FTYPE_Variable] THEN RETURN
IF (self.type<=farray[FTYPE_Min])
endf(self.args[0])
endf(self.args[1])
k:=self.args
END k[2]
ELSEIF self.type >= farray[FTYPE_Red]
endf(self.args[1])
endf(self.args[2])
k:=self.args
END k[3]
ELSE
endf(self.args)
ENDIF
self.type:=farray[FTYPE_None] -> So that if this function is end-ed another time, no harm will be done..
ENDPROC
PROC endf(fun:PTR TO function)
IF fun > 0 THEN END fun
ENDPROC